package com.sun.showcase.controller.basic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sun.showcase.biz.basic.service.GroupResourceService;
import com.sun.showcase.biz.basic.service.ResourceInfoService;
import com.sun.showcase.client.domain.basic.GroupResource;
import com.sun.showcase.client.query.basic.GroupResourceQuery;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;

@Controller
@RequestMapping(value="/basic/groupResource") 
public class GroupResourceController{
	
	@Autowired
	private GroupResourceService groupResourceService;
	
	private Result result = new Result();
	
	//author wx  获取组资源
	@ResponseBody
	@RequestMapping(value = "/getGroupResource")
	public GroupResourceQuery getGroupResource(GroupResourceQuery groupResourceQuery){
		
		String[] checkedIds = this.groupResourceService.findByCheckedIds(groupResourceQuery.getGroupId());
		
		groupResourceQuery.setUpRsIds(checkedIds);
		
		return groupResourceQuery;
	}
	
	/**
	 * 跳转到GroupResource管理页面
	 * 
	 * @return
	 */
	@RequestMapping(value="goGroupResource")
	public String goGroupResource() {
		return "basic/groupResource";
	}
	/**
	 * 跳转到GroupResource新增页面
	 * 
	 * @return
	 */
	@RequestMapping(value="handleGroupResource")
	public String handleGroupResource(@RequestParam(value="id",required=false) Long id ,ModelMap map) {
		return "basic/groupResource_rowEdit";
	}

	/**
	 * 跳转到查看desc页面
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showDesc")
	public GroupResource showDesc(GroupResourceQuery groupResourceQuery) {
		return groupResourceService.get(groupResourceQuery);
	}

	/**
	 * 获得分页数据表格
	 */
	@ResponseBody
	@RequestMapping(value = "/datagrid")
	public DataGrid datagrid(GroupResourceQuery groupResourceQuery) {
		return groupResourceService.datagrid(groupResourceQuery);
	}
	

	/**
	 * 添加一个GroupResource
	 */
	@ResponseBody
	@RequestMapping(value="add")
	public Result add(GroupResourceQuery groupResourceQuery) {
		groupResourceService.add(groupResourceQuery);
		result.setSuccess(true);
		result.setMsg("添加成功！");
		return result;
	}

	/**
	 * 编辑GroupResource
	 */
	@ResponseBody
	@RequestMapping(value="edit")
	public Result edit(GroupResourceQuery groupResourceQuery) {
		groupResourceService.update(groupResourceQuery);
		result.setSuccess(true);
		result.setMsg("编辑成功！");
		return result;
	}

	/**
	 * 物理删除GroupResource
	 */
	@ResponseBody
	@RequestMapping(value="delete")
	public Result delete(GroupResourceQuery groupResourceQuery) {
		groupResourceService.delete(groupResourceQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
	
	/**
	 * 逻辑删除GroupResource
	 */
	@ResponseBody
	@RequestMapping(value="deletePt")
	public Result deletePt(GroupResourceQuery groupResourceQuery) {
		groupResourceService.deletePt(groupResourceQuery.getIds());
		result.setSuccess(true);
		result.setMsg("删除成功！");
		return result;
	}
}
